﻿@using Newtouch.Infrastructure;
@using Newtouch.Common.Operator;
@{
    Layout = "~/Views/Shared/_Index.cshtml";
    var opeator = OperatorProvider.GetCurrent();
}
<script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/wdtree/tree.js")"></script>
<link href="@SiteUrl.GetStaticResourceScriptUrl("~/js/wdtree/tree.css")" rel="stylesheet" />
<script src="~/Content/js/BootstrapMenu.min.js"></script>
<div class="topPanel">
    <div class="search">
        <table>
            <tr>
                <td class="formValue formDdlSelectorTd">
                    <select class="form-control" style="width:45px;height:17px;" id="mbqx" onchange="mbqxquery()">
                        <option value="0" selected="selected">通用</option>
                        <option value="1">个人</option>
                        <option value="2">科室</option>
                    </select>
                </td>
                <td class="formValue">
                    <input id="txt_keyword" type="text" class="form-control" onblur="mbqxquery()" onkeypress="keypress()" placeholder="模板名称" style="width:80px;height:17px;">
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="dv_Medlist" class="gridPanel" style="height:90%">
    <table id="gridList"></table>
</div>
<script>
    $(function () {
        gridList();
    })
    function mbqxquery() {
        mbmxquery();
    }
    function keypress()
    {
        if(event.keyCode==13) 
            mbmxquery();
    }

    function mbmxquery() {
        $("#gridList").jqGrid('setGridParam', {
            postData: { keyValue: $("#txt_keyword").val() , mbqx: $("#mbqx").val() },
        }).trigger('reloadGrid');
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            treeGrid: true,
            treeGridModel: "adjacency",
            ExpandColumn: "expanded",
            url: "/SystemManage/Common/GetBlmbTreeList",
            postData: { keyValue: $("#txt_keyword").val(), mbqx: "0" },
            height: $(window).height() - 120,
            width: $(window).width()-20,
            colModel: [
                { label: "病历模板Id", name: "Id", key: true, hidden: true },
                { label: "Turl", name: "Turl", hidden: true },
                { label: "病历模板", name: "mbmc",width:30 },
            ],
            onSelectRow: function (rowid, status) {
                if (status == true) {
                    debugger;
                    var rowData = $("#gridList").jqGrid('getRowData', rowid);
                    if (rowData.isLeaf == false || rowData.isLeaf == "false") {//禁用条件
                    } else {
                        var param = { 'mbmc': rowData.mbmc, 'Turl': rowData.Turl };
                        window.parent.postMessage(param, '*');
                    }
                }
            },
            onRightClickRow: function (rowid, irow, icol, e) {
                var rowData = $("#gridList").jqGrid('getRowData', rowid);
                if (rowData.isLeaf == false || rowData.isLeaf == "false") {//禁用条件
                } else {
                    initrightMenu(rowData);
                }
            }


        });
    }
    //右键菜单
    function initrightMenu(rowData) {
       var p = '.gridPanel tr[id=' + rowData.Id + ']';
        var menu = new BootstrapMenu(p, {
            //fetchElementData获取元数据
            fetchElementData: function ($rowElem) {
                var data = rowData;
                return data;    //return的目的是给下面的onClick传递参数
            },
            actions: [{
                name: '<span class="glyphicon glyphicon-remove" style="color: rgb(28, 179, 173); font-size: 13px;"></span> 删除模板',
                width: 300,
                onClick: function (obj) {
                    $.deleteForm({
                        url: "/MedicalRecordManage/MedRecordTemplate/DeleteForm",
                        param: { keyValue: rowData.Id },
                        success: function (data) {
                            if (data.state == "success") {
                                $.modalAlert('删除成功', 'success');
                            }
                            else {
                                $.modalAlert(data.message, 'error');
                            }
                            mbmxquery();
                        }
                    })
                }
                }
           ]
        });
    }
</script>
